#include<iostream>
#include<stdio.h>
#include<malloc.h>
using namespace std;
 
#define SIZE 100
typedef int ElemType;
typedef int CLC;
 
typedef struct SqStack {
	ElemType* elem;
	int top_0;
	int top_1;
}SqStack;
CLC InitStack(SqStack* S) {
	S->elem = (int*)malloc(SIZE * sizeof(ElemType));
	S->top_0 = -1;
	S->top_1 = SIZE;
	return true;
}
CLC Push(SqStack* S) {
	if (S->top_0 + 1 == SIZE) {
		printf("栈已满了，无法进栈，如栈程序退出！！！\n");
		return false;
	}
	printf("请输入你要入栈的数据个数：");
	int Num;
	scanf_s("%d", &Num);
	for (int i = 0; i < Num && i < SIZE; i++) {
		scanf_s("%d", &S->elem[i]);
		S->top_0 = i;
	}
	return true;
}
CLC Display(SqStack* S) {
	if (S->top_0 == -1) {
		printf("栈为空，无法输出，程序退出！！！\n");
		return false;
	}
	for (int i = S->top_0; i >= 0; i--) {
		printf("%d ", S->elem[i]);
	}
	return true;
}
CLC POP(SqStack* S) {
	if (S->top_0 == -1) {
		printf("栈为空，程序退出！！\n");
		return false;
	}
	printf("Pop掉最高点的数据%d\n", S->elem[S->top_0]);
	S->top_0--;
	return true;
}
int main()
{
	int i;
	string answer;
	SqStack S;
	while (true) {
	start:
		printf("======Belongs to CLC======\n");
		printf("======1.建立并初始化栈======\n");
		printf("======2.向栈进行入栈操作======\n");
		printf("======3.将栈中的数据输出======\n");
		printf("======4.对栈进行Pop操作======\n");
		printf("======5.获取栈的长度======\n");
		printf("======6.清空顺序栈======\n");
		printf("======0.退出程序======\n");
		printf("请输入数字进行操作：\n");
		scanf_s("%d", &i);
		switch (i) {
		case 1:
			InitStack(&S);
			printf("建立并初始化栈完毕！！\n");
			system("pause");
			system("cls");
			goto start;
		case 2:
			Push(&S); 
			printf("进栈完毕！！\n");
			system("pause");
			system("cls");
			goto start;
		case 3:
			Display(&S); 
			printf("\n输出数据完毕！！\n");
			system("pause");
			system("cls");
			goto start;
		case 4:
			POP(&S);
			printf("进行POP程序完成！！！\n");
			system("pause");
			system("cls");
			goto start;
		case 5:
			printf("栈的长度为：%d\n", S.top_0 + 1);
			system("pause");
			system("cls");
			goto start;
		case 6:
			InitStack(&S);
			printf("清空栈完毕！！\n");
			system("pause");
			system("cls");
			goto start;
		case 0:
			printf("确定退出程序吗？(yes or no)：");
			cin >> answer;
			if (answer == "yes" || answer == "YES")exit(0);
			if (answer == "no" || answer == "NO") {
				system("pause");
				system("cls");
				goto start;
			}
			else {
				printf("输入指令有误,程序继续！！\n");
				system("pause");
				system("cls");
				goto start;
			}
		}
 
	}
	return 0;
}